#include <stdio.h>

int main() {
    int a, b, c, d;
    for (a = 1; a <= 431; a++) {
        for (b = 1; b <= (861 - 2 * a); b++) {
            for (c = 1; c <= (861 - 2 * a - 3 * b); c++) {
            	d=(1496-5 * a + 4 * b + 3 * c)/2;
                if (4 * a + 2 * b + 6 * c + 3 * d == 1175 &&
                    3 * a + b + 7 * c + 5 * d == 958 &&
                    2 * a + 3 * b + 5 * c + d == 861) {
                    printf("%d", b);
                    return 0;
                }
            }
        }
    }
    printf("-1");
    return 0;
}